package com.ymtms.applicationsystem.controller;

import com.ymtms.applicationsystem.pojo.Emp;
import com.ymtms.applicationsystem.pojo.EmpDel;
import com.ymtms.applicationsystem.service.EmpService;
import com.ymtms.applicationsystem.vo.RequestBean;
import com.ymtms.applicationsystem.vo.Result;
import com.ymtms.applicationsystem.vo.ResultUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * @auther: autumn-luo
 * @description:
 * @createTime: 2019-10-22 10:40
 */
@Log4j2
@Controller
@CrossOrigin
public class EmpController {
    @Autowired
    EmpService empService;


    @RequestMapping("/empUpdate")
    @ResponseBody
    /*
     * @createTime 2019-10-25 22:08
     * @author autumn-luo
     * @param: emp
     * @return:
     * @description: 职员更新
     */
    public ResultUtil empUpdate(@Valid Emp emp) {
        log.info("empUpdate:" + emp);
        empService.empUpdate(emp);
        return ResultUtil.success();
    }

    @RequestMapping("/empDel")
    @ResponseBody
    /*
     * @createTime 2019-10-24 17:54
     * @author autumn-luo
     * @param: empDelId 对应前端数据传来的eiid
     * @return:
     * @description: 职员软删除
     */
    public ResultUtil empDel(@Valid EmpDel empDel) {
        int empDelResult = empService.empDel(empDel.getEmpDelId());
        return ResultUtil.success(empDelResult);
    }

    /*
     * @createTime 2019-10-23 15:50
     * @author autumn-luo
     * @param: params 前端layui传过来的一些数据
     * @return: 返回所有的emp给前端
     * @description: 职员查询带分页
     */
    @RequestMapping("/empAll")
    @ResponseBody
    public ResultUtil empGetAll(
            RequestBean empRequest,
            @RequestParam(value = "empSeekInfo", required = false) String empSeekInfo) {
        log.info("empRequest:" + empRequest);
        Result<Emp> empAll = empService.empGetAll(empRequest, empSeekInfo);
        return ResultUtil.success(empAll);
    }

    /*
     * @createTime 2019-10-22 12:18
     * @author autumn-luo
     * @param: emp 前端返回的emp对象
     * @return:
     * @description:  添加职员
     */
    @RequestMapping("/empAdd")
    @ResponseBody
    public ResultUtil empAdd(@Valid Emp emp) {
        log.info("empAdd:" + emp);
        empService.empAdd(emp);
        return ResultUtil.success();
    }
}
